package com.springcloud.controller;

import com.springcloud.dto.WebResultDto;
import com.springcloud.model.BinNoPosModel;
import com.springcloud.model.TaskModel;
import com.springcloud.service.BinNoInfoService;
import com.springcloud.service.TaskExeService;
import com.springcloud.utils.ListUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Transactional
@Slf4j
public class TaskShowController {
    @Resource
    private TaskExeService  taskService;
    @Resource
    private BinNoInfoService binNoInfoService;

    /**
     * 查询单个任务
     */
    @PostMapping("/getTaskInfo")
    public WebResultDto getTaskInfo(@RequestBody TaskModel model){
        WebResultDto result = new WebResultDto();
        if(!model.valid()){
            result.setInfo("参数有误");
            return result;
        }
        List<TaskModel>list=taskService.getTaskInfo(model);
        if (list == null||list.size()<=0) {
            result.setInfo("任务不存在");
            return result;
        }
        result.success(ListUtil.reverseList(list));
        return result;
    }

    /**
     * 刷新任务
     *
     */
    @PostMapping("/refreshTask")
    public WebResultDto refreshTask() {
        WebResultDto result = new WebResultDto();
        result.success(ListUtil.reverseList(taskService.refreshTask()));
        return result;
    }

    /**
     * 获取所有仓位
     *
     */
    @GetMapping("/getBinNoInfo")
    public WebResultDto getBinNoInfo() {
        WebResultDto dto = new WebResultDto();
        List<BinNoPosModel> listRes = binNoInfoService.getAllBinNO();
        if (listRes == null || listRes.size() <= 0) {
            dto.setInfo("无仓位数据");
            return dto;
        }
        dto.success(listRes);
        return dto;
    }
    @GetMapping("/deviceStatus")
    public WebResultDto deviceStatus(){
        WebResultDto webResultDto = new WebResultDto();
        return  webResultDto;
    }
}
